package cn.fangline.wo.task.akka.actors;

import akka.actor.AbstractActor;
import cn.fangline.wo.model.House;
import cn.fangline.wo.model.OriginHouse;
import cn.fangline.wo.task.akka.messages.EndPoint;
import com.baomidou.mybatisplus.mapper.EntityWrapper;

import java.util.List;

/**
 * Created by 抽离 on 2017/6/26 0026.
 */
public class HouseUpdateActor extends AbstractActor {


    @Override
    public Receive createReceive() {
        return
                receiveBuilder()
                        .match(List.class, this::onReceiveUpdateHouseList)
                        .build();
    }

    private void onReceiveUpdateHouseList(List<OriginHouse> originHouses) {
        for(OriginHouse originHouse : originHouses){
            if(originHouse.getId() == null){
                System.out.println("originhouse:" + originHouse);
            }
            originHouse.updateById();
            House house = new House();
            house = house.selectOne(new EntityWrapper<House>().eq("house_id", originHouse.getHouseId()));
            house.setTotalPrice(originHouse.getTotalPrice());
            house.updateById();
            getSender().tell(new EndPoint(), getSelf());
        }
    }
}
